﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;

namespace IETTortak
{
    public class IETTHatListParser
    {
        public static List<string> ParseHatList(byte[] data)
        {
            List<string> ret = new List<string>();

            string hatlistRaw = Regex.Match(Encoding.GetEncoding("iso-8859-9").GetString(data), "<select class=\"input\" name=\"hatcode\">(.*?)</select>", RegexOptions.Singleline).Groups[1].ToString().Trim();
            hatlistRaw = hatlistRaw.Replace(" selected", "");

            Regex re = new Regex("<OPTION value=(?<hatNo>.*?)>.*?</OPTION>", RegexOptions.Singleline);
            MatchCollection mc = re.Matches(hatlistRaw);

            foreach (Match m in mc)
            {
                string hatNo = m.Groups["hatNo"].ToString();
                if (!ret.Contains(hatNo))
                    ret.Add(hatNo);
            }
            return ret;
        }
    }
}
